const wx2my = require('./wx2my');
var base = require('./config.js');
// const Behavior = require('./Behavior');
App({
  globalData: {
    userInfo: null,
    rande: 1
  },
  util: require("./we7/resource/js/util.js"),
  siteInfo: require("./siteinfo.js"),

  onLaunch: function () {
   wx2my.setStorageSync('imgUrl1', 'https://tzlx.tiaze.com/attachment/');
    // getUserInfo().then((userInfo) => {
    //   console.log('userInfo');
    //   console.log(userInfo);
    // }).then(console.log);
  },

  getUserInfo: function (n) {
    var o = this;
    my.getAuthCode({
      scopes: ['auth_user'],
      success: (e) => {
        console.log(e.authCode)
        console.log('获取用户信息啊。。。。。。')
        if (e.authCode) {
          wx2my.newRequest({
            url: base.siteroot,
            data: {
              c:'entry',
              a:'wxapp',
              do:'Login',
              m:'zh_jdgjb',
              auth_code: e.authCode,
              type:'alipay'
            },
            success: (e) => {
              console.log('进入下一层啦啊。。。。。。')
              console.log(e)
              // console.log(e.data.data.list)
              n(e.data);
              wx2my.setStorageSync("userInfo", e.data.data)
            },
            fail: (err) => {
              console.log('错误啦。。。。。。。。。')
              console.log(err)
            }
          });
        }
      }
    });
  },
  max: function (e) {
    e = e[0];
    for (var t = e.length, n = 1; n < t; n++) e[n] > e && (e = e[n]);
    return e;
  },

  today_time: function (e) {
    var t = new Date(),
        n = t.getMonth() + 1,
        o = t.getDate();
    return 1 <= n && n <= 9 && (n = "0" + n), 0 <= o && o <= 9 && (o = "0" + o), t.getFullYear() + "-" + n + "-" + o + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
  },

  hours_time: function (e, t) {
    var n = new Date(e.replace("-", "/")),
        o = 60 * (t = Number(t));
    return n.setMinutes(n.getMinutes() + o, n.getSeconds(), 0), n.getFullYear() + "-" + (n.getMonth() + 1) + "-" + n.getDate() + " " + n.getHours() + ":" + n.getMinutes() + ":" + n.getSeconds();
  },

  today: function () {
    var e = new Date(),
        t = e.getFullYear(),
        n = e.getMonth() + 1,
        o = e.getDate();
    return 1 <= n && n <= 9 && (n = "0" + n), 0 <= o && o <= 9 && (o = "0" + o), t + "-" + n + "-" + o;
  },

  ormatDate: function (e) {
    var t = new Date(1e3 * e);
    return t.getFullYear() + "-" + n(t.getMonth() + 1, 2) + "-" + n(t.getDate(), 2) + " " + n(t.getHours(), 2) + ":" + n(t.getMinutes(), 2) + ":" + n(t.getSeconds(), 2);

    function n(e, t) {
      for (var n = "" + e, o = n.length, a = "", r = t; r-- > o;) a += "0";

      return a + n;
    }
  },

  sort_price_Reverse: function (e, t) {
    return e.zd_money - t.zd_money;
  },

  sort_price_order: function (e, t) {
    return t.zd_money - e.zd_money;
  },

  sort_num_order: function (e, t) {
    return e - t;
  },

  sort_distance_order: function (e, t) {
    return e.distance - t.distance;
  },

  sort_distance_Reverse: function (e, t) {
    return t.distance - e.distance;
  },

  time_title: function (e, t) {
    return !(t <= e) || ( my.alert({
        title: '温馨提醒',
        content: '时间选择错误',
        buttonText: '我知道了',
    }), !1);
  },

  getTime2Time: function (e, t) {
    e = e, t = t;
    return ((e = Date.parse(e) / 1e3) - (t = Date.parse(t) / 1e3)) / 86400;
  },
  
  getSys: function () {
    var t = this;
    wx2my.getSystemInfo({
      success: function (e) {
        t.globalData.sysInfo = e, t.globalData.windowW = e.windowWidth, t.globalData.windowH = e.windowHeight;
      }
    });
  }
});